// pages/index3/index3.js
Page({

    /**
     * 组件的属性列表
     */
    properties: {},

    /**
     * 组件的初始数据
     */
    data: {
        sid: "",
        sel_term: "",
        subs: [{
                name: "2022-2023第二学期",
                id: 2
            },
            {
                name: "2023-2024第一学期",
                id: 3
            },

        ],
        cursubName: "2022-2023第二学期",
        list: [{
                kc: '高等数学',
                classid: 522,
                garde: 15,

            },
            {
                kc: 'C语言',
                classid: 523,
                garde: 19,

            },
            {
                kc: '数据结构',
                classid: 524,
                garde: 90,

            }
        ],
        header: [{
                key: 'kc',
                title: '课程'
            },
            {
                key: 'classid',
                title: '课程编号',
            },
            {
                key: 'garde',
                title: '成绩'
            },


        ]
    },
    changes(e) {
        this.setData({
            sel_term: e.detail.selectId
        })
        console.log(e.detail.selectId);
        console.log(e.detail.select);
        // process();
        var that=this
        wx.request({
            url: 'http://vz3q9q.natappfree.cc/getScoreBySid?sid=' + this.data.sid + '&term=' + this.data.sel_term,
            method: 'POST',
            data: {
                rnum: 2,
                username: 'test1'
            },
            header: {
                'content-type': 'application/x-www-form-urlencoded'
            },
            dataType: 'json',
            success(res) {
                console.log(res.data);
                that.setData({
                    list: res.data.data,
                    header: res.data.headers
                });
            }
        });
    },
    onLoad() {
        const pages = getCurrentPages()
        const prevPage = pages[pages.length - 1] // 获取A页面实例
        const id = prevPage.options.id // 获取A页面传递的id参数
        this.setData({
            sid: id
        })
        console.log(id)
        var that=this
        wx.request({
            url: 'http://vz3q9q.natappfree.cc/getScoreBySid?sid=' + id + '&term=2',
            method: 'POST',
            data: {
                rnum: 2,
                username: 'test1'
            },
            header: {
                'content-type': 'application/x-www-form-urlencoded'
            },
            dataType: 'json',
            
            success(res) {
                console.log(res.data);
                that.setData({
                    list: res.data.data,
                    header: res.data.headers
                });
            }
        });

    }
})